package com.briup.ch06.extend;

public class Son extends Father{
    static{
        System.out.println("子类的静态代码块");
    }
    {
        System.out.println("子类构造代码块");
        address="昆山";
    }
    public String name;
    public Son(){
        System.out.println("子类无参构造器");
    }
    public Son(String name){
        this.name=name;
        System.out.println("子类一参数构造器");
    }
    public Son(String name,String address
            ,double price,String car,
               String computer){

        super(address,price,car,computer);
        this.name=name;
        System.out.println("子类的有参构造器");
        /*
        this.address=address;
        this.setPrice(price);
        this.car=car;
        this.computer=computer;

         */
    }
    public void surfing() {
        System.out.println("儿子会上网冲浪");
    }
    //同包下子类：只能访问父类的非私有的数据
    public void show2(){
        System.out.println("子类访问父类："
                +this.address+super.car
                +computer);
    }
    //重写：子类重写了父类的同名方法
    @Override
    public void show(){
        System.out.println("子类访问父类："
                +this.address+super.car
                +computer);
    }
    //出现同名的方法或者变量，可以通过
    //this/super区分访问是自己的还是父类的
    public void print(){
        show();//this.show()
        this.show();
        super.show();
    }
}
